<#-- Created by IntelliJ IDEA.
 User: qiguoqing
 Date: 2020/11/14
 Time: 11:06
 To change this template use File | Settings | File Templates.-->
<#-- 2020-12-16日改为字典设置页面 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>字典设置</title>
    <meta name="renderer" content="webkit">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <#--   <link rel="stylesheet" href="${re.contextPath}/plugin/lay/layui/css/layui.css">-->
    <!--layui样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/layui/css/layui.css" media="all"/>
    <!--公用样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/comment.css"/>
    <!--页面样式-->
    <link rel="stylesheet" type="text/css" href="${re.contextPath}/plugin/common/css/style.css"/>
    <!--扩展样式-->
    <link rel="stylesheet" href="${re.contextPath}/plugin/common/css/extended.css">
    <script type="text/javascript" src="${re.contextPath}/plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${re.contextPath}/plugin/layui/layui.all.js" charset="utf-8"></script>
    <#--    <script type="text/javascript" src="${re.contextPath}/plugin/lay/layui/layui.js"-->
    <#--            charset="utf-8"></script>-->
    <style>
        .project {
            margin-top: 20px;
            padding: 0px;

        }
        .layui-table-header .layui-table-cell{
            height:auto;
            overflow:visible;
            text-overflow:inherit;
            white-space:initial;
            word-break: break-word;
        }
    </style>
</head>
<body class="whitebg">
<div class="layui-row">
    <div class="layui-col-xs6 layui-col-md4" style="width:33%">
        <div class="demoTable1" style="padding:10px 0px 0px 20px">
            字典类型名称：
            <div class="layui-inline">
                <input class="layui-input" id="dictTypeNameInput">
            </div>
            <input type="button" class="layui-btn" onclick="searchDictType()" value="搜索">
            <input type="button" class="layui-btn layui-btn-danger" onclick="clearSearchDictType()" value="清除">
        </div>
        <div style="padding: 0px 20px 0px 20px">
            <table id="typeList" style="height: 300px;width:100%;margin-left: 2px" class="layui-hide" lay-filter="type"
                   width="100%" data-type="getType"></table>
        </div>
    </div>
    <div class="layui-col-xs12 layui-col-md8" style="width:67%">
        <div class="demoTable1" style="padding:10px 0px 0px 0px">
            字典名称：
            <div class="layui-inline">
                <input class="layui-input" id="dictNameInput">
            </div>
            <input type="button" class="layui-btn" id="dictSearchBtn" onclick="searchDict()" value="搜索">
            <input type="button" class="layui-btn layui-btn-danger" onclick="clearSearchDict()" value="清除">
        </div>
        <div style="padding: 0px 20px 0px 0px">
            <table id="dictList" style="width:100%" class="layui-hide" lay-filter="stage"></table>
        </div>
    </div>
</div>

<script type="text/javascript" src="${re.contextPath}/plugin/tools/tool.js"></script>
<script type="text/javascript" src="${re.contextPath}/plugin/tools/cardUtils.js"></script>
<script type="text/html" id="toolBarType">
    <#--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detailType">查看</a>-->
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="editType">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delType">删除</a>
</script>

<script type="text/html" id="toolBarStage">
    <#--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detailStage">查看</a>-->
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="editStage">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delDict">删除</a>
    {{#  if(d.badtTypecode =='LC001' || d.badtTypecode =='WJ001'||d.badtTypecode =='FBZN001'||d.badtTypecode =='BZJSM001'||d.badtTypecode =='ZCXY'||d.badtTypecode =='YSZC'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="editGuide">指南</a>
    {{#  } }}

</script>
<script type="text/html" id="typeToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addAType">新增</button>
        <button class="layui-btn layui-btn-sm" lay-event="reload">重新加载字典</button>
        <#--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>
<script type="text/html" id="stageToolbar">
    <div class="layui-btn-container">
        <button id="add-dict-btn" class="layui-btn layui-btn-sm" lay-event="addADict">新增</button>
        <#--        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <#--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>
<script>
    var inC = 1;
    var layer;
    var form = layui.form;
    var table = null;
    var tableIns = null;
    var tableIns2 = null;
    var currDictType;
    document.onkeydown = function (e) { // 回车提交表单
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            $(".select .select-on").click();
        }
    }

    var stageId = null;
    //注意进度条依赖 element 模块，否则无法进行正常渲染和功能性操作
    var element = "";
    layui.use('element', function () {
        element = layui.element;
    });
    var dictListCols = [[
        {field: 'badtTypecode',hide: true},
        {field: 'badtIndex', title: '序号', width: '6%'},
        {field: 'badtCode', title: '编号', width: '7%'},
        {field: 'badtName', title: '名称', width: '12%'},
        {field: 'badtGroupid', title: '科室代码', width: '7%'},
        {field: 'badtLevel1', title: '等级1', width: '10%'},
        {field: 'badtLevel2', title: '等级2', width: '10%'},
        {field: 'badtLevel3', title: '等级3', width: '9%'},
        {field: 'badtLevel4', title: '等级4', width: '7%'},
        {field: 'badtLevel5', title: '等级5', width: '7%'},
        // {field: 'badtLevel6', title: '等级6', width: '6%'},
        // {field: 'badtLevel7', title: '等级7', width: '6%'},
        {field: 'badtNote', title: '备注', width: '8%'},
        {field: 'remark', title: '操作', width: '17%', toolbar: "#toolBarStage"}
    ]];
    var wjDictListCols = [[
        {field: 'badtTypecode',hide: true},
        {field: 'badtIndex', title: '序号', width: '6%'},
        {field: 'badtCode', title: '编号', width: '7%'},
        {field: 'badtName', title: '名称', width: '12%'},
        {field: 'badtGroupid', title: '科室代码', width: '7%'},
        {field: 'badtLevel1', title: '等级1', width: '10%'},
        {field: 'badtLevel2', title: '模板主键', width: '8%'},
        {field: 'badtLevel3', title: '文件流程', width: '8%'},
        {field: 'badtLevel4', title: '是否为监理文档', width: '7%'},
        {field: 'badtLevel5', title: '是否必选', width: '7%'},
        // {field: 'badtLevel6', title: '等级6', width: '6%'},
        // {field: 'badtLevel7', title: '等级7', width: '6%'},
        {field: 'badtNote', title: '允许上传文件类型', width: '8%'},
        {field: 'badtLevel11', title: '允许上传的角色', width: '8%'},
        {field: 'badtLevel13', title: '允许编辑的角色', width: '8%'},
        {field: 'badtLevel14', title: '允许导出的角色', width: '8%'},
        {field: 'remark', title: '是否按照字典名称校验', width: '17%', toolbar: "#toolBarStage"}
    ]];
    layui.use('table', function () {
        table = layui.table;
        element = element;
        //方法级渲染
        tableIns = table.render({
            id: 'typeList',
            elem: '#typeList',
            height: 'full-20',
            url: '/sys/dicttype/list',
            toolbar: '#typeToolbar',
            cols: [[
                {
                    title: '序号', width: '15%', templet: function (res) {
                        return res.LAY_INDEX;
                    }
                },
                {field: 'dictTypecode', title: '编号', width: '26%', sort: false},
                {field: 'dictTypename', title: '名称', width: '34%', sort: false},
                {field: 'remark', title: '操作', width: '25%', toolbar: "#toolBarType"}
            ]],
            page: true,
            done: function (res, currentCount) {
                if (inC == 1) {
                    var firstType = $('.layui-table-view[lay-id="typeList"]').children('.layui-table-box').children('.layui-table-body').find('table tbody tr[data-index="0"]');
                    if (firstType.length > 0) {
                        firstType.click();
                    }
                    inC++;
                }
            }
        });
        table.on('tool(type)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detailType') {
                layer.alert('您所查看的项目类型是：[<label style="color: #00AA91;">' + data.badtName + '</label>]')
            }
            if (obj.event === 'editType') {
                viewEditType(data.dictNo);
            }
            if (obj.event === 'delType') {
                layer.confirm('是否确定删除[<label style="color: #00AA91;">' + data.dictTypename + '</label>]数据?', function (index) {
                    delType(data.dictNo);
                    layer.close(index);
                });
            }
        });
        table.on('row(type)', function (obj) {
            localStorage.setItem("currentType", obj.data.dictTypecode);
            currDictType = obj.data;
            localStorage.setItem("currDictTypeData",JSON.stringify(currDictType));
            setNewDictListTableCols();
            //如果字段中有大文本,那么取消字段的自动换行:
            //方法级渲染
            var tableCols = dictListCols;
            if(obj.data.dictTypecode == 'WJ001'){
                tableCols = wjDictListCols;
            }
            tableIns2 = table.render({
                id: 'dictList',
                elem: '#dictList',
                height: 'full-20',
                url: '/sys/dict/getListByTypeCode',
                toolbar: '#stageToolbar',
                cols: tableCols,
                page: false,
                where: {badtTypecode: obj.data.dictTypecode},
                done: function (res, currentCount) {
                    //***重点***：table渲染完成后渲染element进度条
                }
            });
            table.on('tool(stage)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detailStage') {
                    layer.alert('您所查看的项目阶段是：[<label style="color: #00AA91;">' + data.stageName + '</label>]')
                }
                if (obj.event === 'editStage') {
                    viewEditDict(data);
                }
                if (obj.event === 'delDict') {
                    layer.confirm('是否确定删除[<label style="color: #00AA91;">' + data.badtName + '</label>]数据?', function () {
                        delDict(data);
                    }, function (index) {
                        layer.close(index);
                    });
                }
                if (obj.event === 'editGuide') {
                    var badtTypecode = obj.data.badtTypecode;
                    var title = '';
                    var w = "";
                    var h = "";
                    if (w == null || w == '') {
                        w = ($(window).width());
                    }
                    if (h == null || h == '') {
                        h = ($(window).height());
                    }
                    if(badtTypecode == 'LC001' || badtTypecode == 'WJ001'||badtTypecode == 'FBZN001'||badtTypecode == 'BZJSM001'||badtTypecode == 'ZCXY'||badtTypecode == 'YSZC'){
                        title = obj.data.badtName;
                        //打开里程指南编辑页面
                        var artType = "";
                        if(badtTypecode == 'LC001'){
                            artType = "001";
                        }else if(badtTypecode =='WJ001'){
                            artType = "002";
                        }else if(badtTypecode =='FBZN001'){
                            artType = "004";
                        }else if(badtTypecode =='BZJSM001'){
                            artType = "005";
                        }else if(badtTypecode =='ZCXY'){
                            artType = "006";
                        }else if(badtTypecode =='YSZC'){
                            artType = "007";
                        }
                        layer.open({
                            type: 2,
                            area: [w + 'px', h + 'px'],
                            fix: false,
                            maxmin: false,
                            shadeClose: false,
                            shade: 0.4,
                            title: "编辑指南----"+title,
                            content: '/adminManager/supervisor/milepostManager/showEditGuide?artType='+artType+'&id='+obj.data.badtCode+'&title='+title,
                            yes: function(){
                                alert(8888);
                            },
                            btn2: function(){
                                layer.closeAll();
                            },

                            zIndex: layer.zIndex, //重点1,
                            success: function(layero){
                                layer.setTop(layero); //重点2
                            },
                            end: function () {
                                tableIns2.reload();
                            }
                        });
                    }else{
                        layer.msg("开发中...");
                    }
                }
            })
            table.on('toolbar(stage)', function (obj) {
                switch (obj.event) {
                    case 'addADict':
                        addDict();
                };
            })
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });
        table.on('toolbar(type)', function (obj) {
            switch (obj.event) {
                case 'addAType':
                    addType();
                case 'reload':
                    reloadDict();

            };
        })
    })
    $(function(){
        $('#dictTypeNameInput').bind('keypress',function(event){
            if(event.keyCode == "13") {
                searchDictType();
            }
        });
        $('#dictNameInput').bind('keypress',function(event){
            if(event.keyCode == "13") {
                searchDict()
            }
        });
    });

    function setNewDictListTableCols(){
        for(var i=1;i<8;i++){
            var currLevelName = '';
            eval("currLevelName=currDictType['dictLevel'+i+'Name']");
            if(currLevelName){
                dictListCols[0][(i*1)+4].title= currLevelName;
            }else{
                dictListCols[0][(i*1)+4].title= '等级'+i;
            }
        }
    }

    function delType(dictNo) {
        layerAjax('/sys/dicttype/delType', {dictNo: dictNo}, '', function (d) {
            if (d.flag == true) {
                inC = 1;
                layui.table.reload('typeList');
                layer.msg('操作成功', {icon: 1});
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });
    }

    function delDict(data) {
        layerAjax('/sys/dict/deleteDict', {badtNo: data.badtNo}, '', function (d) {
            if (d.flag == true) {
                layui.table.reload('dictList');
                layer.msg("操作成功", {icon: 1});
            } else {
                layer.msg(d.msg, {icon: 1});
            }
        });
    }

    function delMilepost(id) {
        layerAjax('/adminManager/supervisor/milepostManager/delMilepost', {id: id}, '', function (d) {
            if (d.flag == true) {
                layui.table.reload('milepostList');
                layer.msg("操作成功", {icon: 1});
            } else {
                layer.msg(d.msg, {icon: 1});
            }
        });
    }

    function reloadDict() {
        layerAjax('/sys/dict/reloadDict', {id: ''}, '', function (d) {
            if (d.flag == true) {
                layer.msg(d.msg, {icon: 1});
            } else {
                layer.msg(d.msg, {icon: 2});
            }
        });
    }


    function addType() {
        var w = ($(window).width() * 0.9);
        var h = ($(window).height() - 50);
        layer.open({
            id: 'type-add',
            type: 2,
            area: ['380px', '220px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: "新增字典类型",
            content: ['/sys/dicttype/showAdd', 'no'],
            yes: function () {
                alert(8888);
            },
            btn2: function () {
                layer.closeAll();
            },
            zIndex: layer.zIndex, //重点1,
            success: function (layero) {
                layer.setTop(layero); //重点2
            },
            end: function () {
                tableIns.reload();
            }
        });
    }

    function addDict() {
        var w = ($(window).width() * 0.9);
        var h = ($(window).height() - 50);
        var currentType = localStorage.getItem("currentType");
        if (!currentType) {
            layer.msg("没有选择的项目类型", {icon: 2});
            return;
        }
        var height = "430px";
        if(currentType == 'WJ001'){
            height = "470px";
        }
        layer.open({
            id: 'stage-add',
            type: 2,
            area: ['760px', height],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: "新增字典",
            content: ['/sys/dict/showAddDict', 'no']
        });
    }

    function viewEditType(dictNo) {
        // var w = ($(window).width() * 0.9);
        // var h = ($(window).height() - 50);
        layer.open({
            id: 'type-update',
            type: 2,
            area: ['380px', '230px'],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: "更新字典类型",
            content: ['/sys/dicttype/showUpdateType?dictNo=' + dictNo, 'no']
        });
    }

    function viewEditDict(data) {
        var currentType = localStorage.getItem("currentType");
        var w = ($(window).width() * 0.7);
        var h = ($(window).height() - 400);
        var height ='420px';
        if(currentType=='WJ001'){
            height ='470px';
        }
        layer.open({
            id: 'stage-update',
            type: 2,
            area: [w + 'px', height],
            fix: false,
            maxmin: true,
            shadeClose: false,
            shade: 0.4,
            title: "更新字典",
            content: ['/sys/dict/showUpdate?badtNo=' + data.badtNo, 'no']
        });
    }


    function queryMilepost(id) {
        // alert(id)
        var id = id;
        localStorage.setItem("currentStageId", id);
        var jsondata = {
            stageId: id,
        };
        table.reload('milepostList', {
            where: jsondata
        });
    }

    function searchDictType(){
        var dictTypename = $('#dictTypeNameInput').val();
            inC = 1;
            tableIns.reload({
                where: {
                    dictTypename: dictTypename
                }
            });
    }

    function searchDict(){
        var dictName = $('#dictNameInput').val();
            inC = 1;
            tableIns2.reload({
                where: {
                    badtName: dictName,
                }
            });
    }

    function clearSearchDictType(){
        $('#dictTypeNameInput').val('');
        inC = 1;
        tableIns.reload({
            where: {
                dictTypename: ''
            }
        });
    }
    function clearSearchDict(){
        $('#dictNameInput').val('');
        inC = 1;
        tableIns2.reload({
            where: {
                badtName: '',
            }
        });
    }

    function flushTypeList() {
        tableIns.reload();
    }

    function flushDictList() {
        tableIns2.reload();
    }

    function clearLayuiTable(id) {
        table.reload(id, {
            where: ''
        });
    }
</script>
</body>

</html>